<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数字类型</title>
    <script src="js/vue.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        .add{
            width: 500px;
            margin: 10px auto;
        }
        .table {
            width: 400px;
            margin: 10px auto;
        }
        .table .item{
            float: left;
            width: 100px;
            height: 40px;
            text-align: center;
            line-height: 40px;
            background-color: black;
            color: burlywood;
        }

    </style>
</head>

<body>

    <div id="app">
        <div class="add">
            用户<input v-model="username"/>
            年龄<input v-model="userage"/>
            <button @click="add">新增</button>
        </div>
        <div class="table">
            <div class="tr">
                <div class="item">编号</div>
                <div class="item">姓名</div>
                <div class="item">年龄</div>
                <div class="item">操作</div>
            </div>
            <div class="tr" v-for="item in list" :key="item.id">
                <div class="item">{{item.id}}</div>
                <div class="item">{{item.username}}</div>
                <div class="item">{{item.userage}}</div>
                <div class="item" @click="del(item.id)">删除</div>
            </div>
        </div>

    </div>
</body>
<script>
    new Vue({
        el: "#app",
        data: {
            username:"",
            userage:"",
            list: [{ id: 1, username: "leson", userage: 18 }, { id: 2, username: "lili", userage: 28 }, { id: 3, username: "lala", userage: 19 }]
        },
        methods: {
            del(id){//点的3   
                this.list = this.list.filter(item=>item.id!=id);//不要3
            },
            add(){
               // alert(this.username+"年龄"+this.userage);

               //判断用户名是否存在

               this.list.push({
                   id:this.list.length>=1?this.list[this.list.length-1].id+1:1,//取出集合最后一个元素的的属性id 在加1
                   username:this.username,
                   userage:this.userage

               })


               


            }

        },
        watch: {

        }
    })
</script>

</html>